package com.sm.tests;

import com.sm.binder.NameMatcher;

import java.util.Map;
import java.util.HashMap;

/**
 * Author: Sergejs Melderis
 */
public class BlogNameMatcher implements NameMatcher {
    static final Map<String, String> classToTable =
            new HashMap<String, String>();

    static {
        classToTable.put("Category", "CATEGORIES");
        classToTable.put("Post", "POSTS");
        classToTable.put("User", "USERS");
    }


    public boolean matches(String className, String tableName,
                           String methodName, String columnName) {

        if (!classToTable.get(className).equals(tableName))
            return false;

        if (!methodName.startsWith("set"))
            return false;

        if (methodName.length() == 3)
            return false;

        String setter = methodName.substring(3);
        String parts[] = columnName.split("_");
        String name = "";
        for (String part : parts)
            name += part;
        return setter.equalsIgnoreCase(name);
    }
}

